<template>

  <el-dialog v-model="crud.dialogFormVisible" :title="crud.formtitle" width="520px">
    <el-form :model="crud.form" :label-width="crud.formLabelWidth">




      <el-form-item label="名称:" prop="name">
        <el-input v-model="crud.form.name" />
      </el-form-item>
      <el-form-item label="标识" prop="label">
        <el-input v-model.number="crud.form.label" />
      </el-form-item>


      <el-form-item label="部门" prop="depts">
        <treeselect v-model="crud.form.depts" :options="deptlist" multiple style="width: 400px" placeholder="选择部门" />
      </el-form-item>



      <el-form-item label="描述信息" prop="remark">
        <el-input v-model="crud.form.remark" type="textarea" />
      </el-form-item>



    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="crud.dialogFormVisible = false">取消</el-button>
        <el-button type="primary" @click="crud.submitCU()">确定</el-button>
      </span>
    </template>
  </el-dialog>

</template>
<script setup lang="ts">
import { crud, CRUD } from '/@/crud/crud';
import { roleinfo } from '/@/api/system/role';
import 'vue3-treeselect-ts/dist/style.css'
import { pick } from 'lodash-es';
import Treeselect from 'vue3-treeselect-ts'
crud.form.menus = []
console.log("test")
const props = defineProps({
  deptlist: { type: Array },
});

searchinfo()
function searchinfo() {
  console.log(props.deptlist);
  if (crud.formtitle == '编辑角色') {
    crud.form.roleId = crud.form.id
    roleinfo({ roleId: crud.form.id }).then(res => {
      crud.form.depts = res.data.depts.map(res => {
        return res.departmentId
      })
      crud.form.menus = res.data.menus.map(item => {
        return item.menuId
      })

      crud.form = pick(crud.form, 'roleId', 'remark', "name", "menus", "label", "depts")
    })
  }
}
</script>